c<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');
if ( ! function_exists('bootstrap_form'))
{
	function bootstrap_form($action,$descripcion, $_id, $attributes='',$hidden='',$upload=false)
	{
		//$hidden = array('username' => 'Joe', 'member_id' => '234');
		//$attributes= array('class' => 'form-horizontal', 'id' => $_id);
        if (!isset($attributes['class'])){
            $attributes['class'] ='form-horizontal';
        }
		$attributes['id'] =$_id;
		$out="";
		if ($upload==false){
			$out.=form_open($action, $attributes,$hidden);
		}else{
			$out.=form_open_multipart($action, $attributes,$hidden);
		}
        if ($descripcion!=''){
            $out.='<fieldset>
			<div id="legend" class="">
        		<legend class="">'.$descripcion.'</legend>
      		</div>';
        }
      	return $out;

	}
}
if ( ! function_exists('bootstrap_form_close'))
{
	function bootstrap_form_close($submit,$cancelar,$nuevo=true)
	{      
	   $out='<div class="form-actions">';
        if($submit){
            if ($nuevo){
                $out.='<button type="submit" class="btn btn-primary">'.$submit.'</button>';
            }else{
                $out.='<button type="submit" class="btn btn-warning">'.$submit.'</button>';
            }
            
        }
        if($cancelar){
            $out.='<button type="button" class="btn">'.$cancelar.'</button>';
        }
        $out.='</div>';
		$out.=form_close();
		return $out;
	}
}

if ( ! function_exists('bootstrap_form_input'))
{

	function bootstrap_form_input($descripcion, $_id,$value='',$placeholder='',$tooltips='',$help_text='',$max_value=100,$min_value='',$requerido=false,$disabled=false)
	{
		$out='<div class="control-group">
          <label class="control-label">'.$descripcion.'</label>
          <div class="controls">
            <input type="text" class="input xlarge" name="'.$_id.'" id="'.$_id.'"';
            if ($value){
            	$out.=' value="'.$value.'" ';
            }
            if ($placeholder){
            	$out.=' placeholder="'.$placeholder.'" ';
            }
            if ($tooltips){
            	$out.=' rel="tooltip" title="'.$tooltips.'" ';
            }
            if ($min_value){
            	$out.=' minlength="'.$min_value.'" ';
            }
            if ($max_value){
            	$out.=' maxlength="'.$max_value.'" ';
            }
            if ($requerido){
            	$out.=' required';
            }
            if ($disabled){
            	$out.=' disabled';
            }
            $out.='/>';
            if ($help_text){
            	$out.='<p class="help-block help-inline">'.$help_text.'</p>';
            }
          $out.='</div>';
          $out.='</div>';
      	return $out;

	}
}
if ( ! function_exists('bootstrap_form_password'))
{
	function bootstrap_form_password($descripcion, $_id,$value='',$placeholder='',$tooltips='',$help_text='',$min_value='',$max_value=100,$requerido=false,$disabled=false)
	{
		$out='<div class="control-group">
          <label class="control-label">'.$descripcion.'</label>
          <div class="controls">
            <input type="password" class="input xlarge" name="'.$_id.'" id="'.$_id.'"';
            if ($value){
            	$out.=' value="'.$value.'" ';
            }
            if ($placeholder){
            	$out.=' placeholder="'.$placeholder.'" ';
            }
            if ($tooltips){
            	$out.=' rel="tooltip" title="'.$tooltips.'" ';
            }
            if ($min_value){
            	$out.=' minlength="'.$min_value.'" ';
            }
            if ($max_value){
            	$out.=' maxlength="'.$max_value.'" ';
            }
            if ($requerido){
            	$out.=' required';
            }
            if ($disabled){
            	$out.=' disabled';
            }
            $out.=' />';
            if ($help_text){
            	$out.='<p class="help-block help-inline">'.$help_text.'</p>';
            }
          $out.='</div>';
          $out.='</div>';
      	return $out;

	}
}
if ( ! function_exists('bootstrap_form_email'))
{
	function bootstrap_form_email($descripcion, $_id,$value='',$placeholder='',$tooltips='',$help_text='',$requerido=false,$disabled=false)
	{
		$max_value=100;
		$out='<div class="control-group">
          <label class="control-label">'.$descripcion.'</label>
          <div class="controls">
            <input type="email" class="input xlarge" name="'.$_id.'" id="'.$_id.'"';
            if ($value){
            	$out.=' value="'.$value.'" ';
            }
            if ($placeholder){
            	$out.=' placeholder="'.$placeholder.'" ';
            }
            if ($tooltips){
            	$out.=' rel="tooltip" title="'.$tooltips.'" ';
            }
            if ($max_value){
            	$out.=' maxlength="'.$max_value.'" ';
            }
            if ($requerido){
            	$out.=' required';
            }
            if ($disabled){
            	$out.=' disabled';
            }
            $out.=' />';
            if ($help_text){
            	$out.='<p class="help-block help-inline">'.$help_text.'</p>';
            }
          $out.='</div>';
          $out.='</div>';
      	return $out;

	}
}
if ( ! function_exists('bootstrap_form_upload'))
{
	function bootstrap_form_upload($descripcion, $_id,$help_text='',$requerido=false,$disabled=false)
	{
		$out='<div class="control-group">
          <label class="control-label">'.$descripcion.'</label>
          <div class="controls">
          	<input class="input-file" type="file" name="'.$_id.'" id="'.$_id.'"';
            if ($requerido){
            	$out.=' required';
            }
            $out.=' />';
            if ($help_text){
            	$out.='<p class="help-block help-inline">'.$help_text.'</p>';
            }
          $out.='</div>';
          $out.='</div>';
      	return $out;

	}
}
if ( ! function_exists('bootstrap_form_dropdown'))
{
    function bootstrap_form_dropdown($descripcion,$_id , $sql, $selected = array(),$help_text='',$requerido=false,$disabled=false,$texto = "")
    {       
	
        $CI =& get_instance();
        $form='<div class="control-group">
          <label class="control-label">'.$descripcion.'</label>
          <div class="controls">';
        if ( ! is_array($selected))
        {
            $selected = array($selected);
        }

        // If no selected state was submitted we will attempt to set it automatically
        if (count($selected) === 0)
        {
            // If the form name appears in the $_POST array we have a winner!
            if (isset($_POST[$_id]))
            {
                $selected = array($_POST[$_id]);
            }
        }       
        $form .= '<select name="'.$_id.'" class="input xlarge" ';
		if ($requerido){
			$form.=' required';
		}
		if ($disabled){
			$form.=' disabled';
		}
        $form.=' />';
        if ($texto){
            $form .= '<option value="0">'.$texto."</option>\n";
        }
        $query=$CI->db->query($sql);
        if(isset($opcion) && $opcion!= null)
            $form .= '<option value="0">Todos</option>\n"';
        
        if ($query->num_rows() > 0)
        {
           foreach ($query->result_array() as $row)
           {
                  $values = array_values($row);
                  if (count($values)===2){
                    $key = (string) $values[0];
                    $val = (string) $values[1];
                    //$this->option($values[0], $values[1]);
                  }

                $sel = (in_array($key, $selected))?' selected="selected"':'';

                $form .= '<option value="'.$key.'"'.$sel.'>'.$val."</option>\n";
           }
        }
        $form .= '</select>';
        if ($help_text){
			$form.='<p class="help-block help-inline">'.$help_text.'</p>';
		}
		$form.='</div>';
        $form.='</div>';
        return $form;
    }
}
if ( ! function_exists('bootstrap_form_textarea'))
{
	function bootstrap_form_textarea($descripcion, $_id,$value='',$placeholder='',$tooltips='',$help_text='',$max_value=100,$min_value='',$requerido=false,$disabled=false)
	{
		$out='<div class="control-group">
          <label class="control-label">'.$descripcion.'</label>
          <div class="controls">
          	<div class="textarea">
                  <textarea rows=3  class="input xlarge"name="'.$_id.'" id="'.$_id.'"';
            if ($placeholder){
            	$out.=' placeholder="'.$placeholder.'" ';
            }
            if ($tooltips){
            	$out.=' rel="tooltip" title="'.$tooltips.'" ';
            }
            if ($min_value){
            	$out.=' minlength="'.$min_value.'" ';
            }
            if ($max_value){
            	$out.=' maxlength="'.$max_value.'" ';
            }
            if ($requerido){
            	$out.=' required';
            }
            if ($disabled){
				$out.=' disabled';
			}
            $out.='>'.$value.'</textarea>';
            if ($help_text){
            	$out.='<p class="help-block help-inline">'.$help_text.'</p>';
            }
          $out.='</div>';
          $out.='</div>';
          $out.='</div>';
      	return $out;

	}
}
if ( ! function_exists('bootstrap_form_dropdown_list'))
{
	function bootstrap_form_dropdown_list($descripcion,$_id , $sql, $selected = array(),$help_text='',$requerido=false,$disabled=false)
    {
        $CI =& get_instance();
        $form='<div class="control-group">
          <label class="control-label">'.$descripcion.'</label>
          <div class="controls">';
        if ( ! is_array($selected))
        {
            $selected = array($selected);
        }

        // If no selected state was submitted we will attempt to set it automatically
        if (count($selected) === 0)
        {
            // If the form name appears in the $_POST array we have a winner!
            if (isset($_POST[$_id]))
            {
                $selected = array($_POST[$_id]);
            }
        }

        $form .= '<select name="'.$_id.'" class="input xlarge"  multiple="multiple" ';
		if ($requerido){
			$form.=' required';
		}
		if ($disabled){
			$form.=' disabled';
		}
        $form.=' />';
        $query=$CI->db->query($sql);
        if ($query->num_rows() > 0)
        {
           foreach ($query->result_array() as $row)
           {
                  $values = array_values($row);
                  if (count($values)===2){
                    $key = (string) $values[0];
                    $val = (string) $values[1];
                    //$this->option($values[0], $values[1]);
                  }

                $sel = (in_array($key, $selected))?' selected="selected"':'';

                $form .= '<option value="'.$key.'"'.$sel.'>'.$val."</option>\n";
           }
        }
        $form .= '</select>';
        if ($help_text){
			$form.='<p class="help-block help-inline">'.$help_text.'</p>';
		}
		$form.='</div>';
        $form.='</div>';
        return $form;
    }
}
if ( ! function_exists('bootstrap_form_label'))
{
	function bootstrap_form_label($descripcion,$controls)
	{
		$out='<div class="control-group">
          <label class="control-label">'.$descripcion.'</label>
          <div class="controls">'.$controls;
          $out.='</div>';
          $out.='</div>';
      	return $out;

	}
}
if ( ! function_exists('bootstrap_checkbox'))
{
	function bootstrap_checkbox($descripcion,$_id,$value='',$checked='',$tooltips='',$help_text='',$min_checked='',$min_mensaje='',$max_checked='',$max_mensaje='',$requerido=false,$disabled=false)
	{
		$out='<label class="checkbox inline">
              	<input type="checkbox" name="'.$_id.'" id="'.$_id.'"';
            if ($value){
            	$out.=' value="'.$value.'" ';
            }
            if ($tooltips){
            	$out.=' rel="tooltip" title="'.$tooltips.'" ';
            }
            if ($min_checked){
            	$out.='data-validation-minchecked-minchecked="'.$min_checked.'" ';
            }
            if ($min_mensaje){
            	$out.=' data-validation-minchecked-message="'.$min_mensaje.'" ';
            }
            if ($max_checked){
            	$out.=' data-validation-maxchecked-maxchecked="'.$max_checked.'" ';
            }
            if ($max_mensaje){
            	$out.=' data-validation-maxchecked-message="'.$max_mensaje.'" ';
            }
            if ($requerido){
            	$out.=' required';
            }
            if ($disabled){
				      $out.=' disabled';
            }
            if ($checked){
            	$out.=' checked="checked." ';	
            }
            $out.='>'.$descripcion.'</label>';
            if ($help_text){
            	$out.='<p class="help-block help-inline">'.$help_text.'</p>';
            }
      	return $out;

	}
}
if ( ! function_exists('bootstrap_radio'))
{
  function bootstrap_radio($descripcion,$_id,$value='',$checked='',$tooltips='',$help_text='',$requerido=false,$disabled=false)
  {
    $out='<label class="radio inline">
                <input type="radio" name="'.$_id.'" id="'.$_id.'"';
            if ($value){
              $out.=' value="'.$value.'" ';
            }
            if ($tooltips){
              $out.=' rel="tooltip" title="'.$tooltips.'" ';
            }
            if ($requerido){
              $out.=' required';
            }
            if ($disabled){
              $out.=' disabled';
            }
            if ($checked){
              $out.=' checked="checked." '; 
            }
            $out.='>'.$descripcion.'</label>';
            if ($help_text){
              $out.='<p class="help-block help-inline">'.$help_text.'</p>';
            }
        return $out;

  }
}
if ( ! function_exists('bootstrap_form_radio'))
{
  function bootstrap_form_radio($label_descripcion,$descripcion,$_id,$value='',$checked='',$tooltips='',$help_text='',$requerido=false,$disabled=false)
  {
    $out='<div class="control-group">
          <label class="control-label">'.$label_descripcion.'</label>
          <div class="controls">';
    $out.='<label class="radio inline">
                <input type="radio" name="'.$_id.'" id="'.$_id.'"';
            if ($value){
              $out.=' value="'.$value.'" ';
            }
            if ($tooltips){
              $out.=' rel="tooltip" title="'.$tooltips.'" ';
            }
            if ($requerido){
              $out.=' required';
            }
            if ($disabled){
              $out.=' disabled';
            }
            if ($checked){
              $out.=' checked="checked." '; 
            }
            $out.='>'.$descripcion.'</label>';
            if ($help_text){
              $out.='<p class="help-block help-inline">'.$help_text.'</p>';
            }
          $out.='</div>';
          $out.='</div>';
        return $out;

  }
}
if ( ! function_exists('bootstrap_form_checkbox'))
{
	function bootstrap_form_checkbox($label_descripcion,$descripcion,$_id,$value='',$checked='',$tooltips='',$help_text='',$min_checked='',$max_checked='',$min_mensaje='',$max_mensaje='',$requerido=false,$disabled=false)
	{
		$out='<div class="control-group">
          <label class="control-label">'.$label_descripcion.'</label>
          <div class="controls">';
		$out.='<label class="checkbox inline">
              	<input type="checkbox" name="'.$_id.'" id="'.$_id.'"';
            if ($value){
            	$out.=' value="'.$value.'" ';
            }
            if ($tooltips){
            	$out.=' rel="tooltip" title="'.$tooltips.'" ';
            }
            if ($min_checked){
            	$out.='data-validation-minchecked-minchecked="'.$min_checked.'" ';
            }
            if ($min_mensaje){
            	$out.=' data-validation-minchecked-message="'.$min_mensaje.'" ';
            }
            if ($max_checked){
            	$out.=' data-validation-maxchecked-maxchecked="'.$max_checked.'" ';
            }
            if ($max_mensaje){
            	$out.=' data-validation-maxchecked-message="'.$max_mensaje.'" ';
            }
            if ($requerido){
            	$out.=' required';
            }
            if ($disabled){
				$out.=' disabled';
			}
            if ($checked){
            	$out.=' checked="checked." ';	
            }
            $out.='>'.$descripcion.'</label>';
            if ($help_text){
            	$out.='<p class="help-block help-inline">'.$help_text.'</p>';
            }
          $out.='</div>';
          $out.='</div>';
      	return $out;

	}
}
if ( ! function_exists('bootstrap_form_number')){
  function bootstrap_form_number($descripcion, $_id,$value='',$placeholder='',$tooltips='',$help_text='',$min_value='',$max_value='',$requerido=false,$disabled=false)
  {
    $out='<div class="control-group">
          <label class="control-label">'.$descripcion.'</label>
          <div class="controls">
            <input type="number" class="input xlarge" name="'.$_id.'" id="'.$_id.'"';
            if ($value){
              $out.=' value="'.$value.'" ';
            }
            if ($placeholder){
              $out.=' placeholder="'.$placeholder.'" ';
            }
            if ($tooltips){
              $out.=' rel="tooltip" title="'.$tooltips.'" ';
            }
            if ($min_value){
              $out.=' min="'.$min_value.'" ';
            }
            if ($max_value){
              $out.=' max="'.$max_value.'" ';
            }
            if ($requerido){
              $out.=' required';
            }
            if ($disabled){
              $out.=' disabled';
            }
            $out.='/>';
            if ($help_text){
              $out.='<p class="help-block help-inline">'.$help_text.'</p>';
            }
          $out.='</div>';
          $out.='</div>';
        return $out;

  }
}
if ( ! function_exists('bootstrap_form_date')){
  function bootstrap_form_date($descripcion, $_id,$value='',$placeholder='',$tooltips='',$help_text='',$requerido=false,$disabled=false)
  {
    $out='<div class="control-group">
          <label class="control-label">'.$descripcion.'</label>
          <div class="controls">
            <input type="text" class="input xlarge date_picker" name="'.$_id.'" id="'.$_id.'"';
            if ($value){
              $out.=' value="'.$value.'" ';
            }
            if ($placeholder){
              $out.=' placeholder="'.$placeholder.'" ';
            }
            if ($tooltips){
              $out.=' rel="tooltip" title="'.$tooltips.'" ';
            }
            if ($requerido){
              $out.=' required';
            }
            if ($disabled){
              $out.=' disabled';
            }
            $out.='/>';
            if ($help_text){
              $out.='<p class="help-block help-inline">'.$help_text.'</p>';
            }
          $out.='</div>';
          $out.='</div>';
        return $out;

  }
}
if ( ! function_exists('bootstrap_form_time')){
  function bootstrap_form_time($descripcion, $_id,$value='',$placeholder='',$tooltips='',$help_text='',$requerido=false,$disabled=false)
  {
    $out='<div class="control-group">
          <label class="control-label">'.$descripcion.'</label>
          <div class="controls">
            <div class="input-append bootstrap-timepicker-component">
            <input type="text" class="input xlarge timepicker" name="'.$_id.'" id="'.$_id.'"';
            if ($value){
              $out.=' value="'.$value.'" ';
            }
            if ($placeholder){
              $out.=' placeholder="'.$placeholder.'" ';
            }
            if ($tooltips){
              $out.=' rel="tooltip" title="'.$tooltips.'" ';
            }
            if ($requerido){
 
              $out.=' required';
            }
            if ($disabled){
              $out.=' disabled';
            }
            $out.='/><span class="add-on"><i class="icon-time"></i>';
            if ($help_text){
              $out.='<p class="help-block help-inline">'.$help_text.'</p>';
            }
          $out.='</div>';
          $out.='</div>';
          $out.='</div>';
        return $out;

  }
}
if ( ! function_exists('bootstrap_modal_warning')){
    function bootstrap_modal_warning($mensaje)
    {
    $out='<div class="modal hide fade in" id="auto_modal">
        <div class="modal-header">
            <a class="close" data-dismiss="modal">&times;</a>
            <h3>Errror</h3>
        </div>
        <div class="modal-body inline">
            <h4><p><img src="'.base_url().'img/ico/warning64.png" class="img-rounded"><span class="help-inline">'.$mensaje.'</span></p></h4>
        </div>
        <div class="modal-footer">
            <button class="btn btn-warning btn-block"  data-dismiss="modal" aria-hidden="true">Aceptar</button>
        </div>
    </div>';
        return $out;
    }
}
if ( ! function_exists('bootstrap_modal_error')){
    function bootstrap_modal_error($mensaje)
    {
    $out='<div class="modal hide fade in" id="auto_modal">
        <div class="modal-header">
            <a class="close" data-dismiss="modal">&times;</a>
            <h3>Error</h3>
        </div>
        <div class="modal-body inline">
            <h4><p><img src="'.base_url().'img/ico/error64.png" class="img-rounded"><span class="help-inline">'.$mensaje.'</span></p></h4>
        </div>
        <div class="modal-footer">
            <button class="btn btn-danger btn-block"  data-dismiss="modal" aria-hidden="true">Aceptar</button>
        </div>
    </div>';
        return $out;
    }
}
if ( ! function_exists('bootstrap_modal_error')){
    function bootstrap_modal_sucess($mensaje)
    {
    $out='<div class="modal hide fade in" id="auto_modal">
        <div class="modal-header">
            <a class="close" data-dismiss="modal">&times;</a>
            <h3>Sucess</h3>
        </div>
        <div class="modal-body inline">
            <h4><p><img src="'.base_url().'img/ico/correcto64.png" class="img-rounded"><span class="help-inline">'.$mensaje.'</span></p></h4>
        </div>
        <div class="modal-footer">
            <button class="btn btn-danger btn-block"  data-dismiss="modal" aria-hidden="true">Aceptar</button>
        </div>
    </div>';
        return $out;
    }
}

if ( ! function_exists('bootstrap_alert_sucess')){
    function bootstrap_alert_sucess($mensaje)
    {
    //<a href="#"><span class="label label-info">Check it now!</span></a>    
    $out='<div class="alert alert-success">
            <button class="close" data-dismiss="alert">x</button>
            <strong>Sucess!</strong>'.$mensaje.'            
        </div>';
        return $out;
    }
}
if ( ! function_exists('bootstrap_alert_error')){
    function bootstrap_alert_error($mensaje)
    {
    //<a href="#"><span class="label label-info">Check it now!</span></a>    
    $out='<div class="alert alert-error">
            <button class="close" data-dismiss="alert">x</button>
            <strong>Error!</strong>'.$mensaje.'            
        </div>';
        return $out;
    }
}
if ( ! function_exists('bootstrap_alert_info')){
    function bootstrap_alert_info($mensaje)
    {
    //<a href="#"><span class="label label-info">Check it now!</span></a>    
    $out='<div class="alert alert-info">
            <button class="close" data-dismiss="alert">x</button>
            <strong>Sucess!</strong>'.$mensaje.'            
        </div>';
        return $out;
    }
}
if ( ! function_exists('bootstrap_modal_eliminar')){
    function bootstrap_modal_eliminar($mensaje)
    {
    $out='<div class="modal hide fade in" id="modal_eliminar">
        <div class="modal-header">
            <a class="close" data-dismiss="modal">&times;</a>
            <h3>Pregunta</h3>
        </div>
        <div class="modal-body inline">
            <h4><p><img src="'.base_url().'img/ico/icon-trash.png" class="img-rounded"><span class="help-inline">'.$mensaje.'</span></p></h4>
        </div>
        <div class="modal-footer">
            <button class="btn btn-large"  data-dismiss="modal" aria-hidden="true">Cancelar</button>
            <a class="btn btn-danger btn-large" id="confirmar_eliminar" aria-hidden="true">Aceptar</a>
        </div>
    </div>';
        return $out;
    }
}
if ( ! function_exists('bootstrap_boton_nuevo')){
    function bootstrap_boton_nuevo($href)
    {    
        $out='<a class="btn btn-success" href="'.$href.'"><i class="icon-file"></i></a>';
        return $out;
    }
}
if ( ! function_exists('bootstrap_boton_editar')){
    function bootstrap_boton_editar($href)
    {    
        $out='<a class="btn btn-warning" href="'.$href.'"><i class="icon-pencil"></i></a>';
        return $out;
    }
}
if ( ! function_exists('bootstrap_boton_eliminar')){
    function bootstrap_boton_eliminar($href)
    {    
        $out='<a class="btn btn-danger eliminar" data-href="'.$href.'"><i class="icon-remove"></i></a>';
        return $out;
    }
}
if ( ! function_exists('bootstrap_boton_sucess')){
    function bootstrap_boton_sucess($href,$text)
    {    
        $out='<a class="btn btn-success" href="'.$href.'">'.$text.'</a>';
        return $out;
    }
}
if ( ! function_exists('bootstrap_boton_info')){
    function bootstrap_boton_info($href,$text)
    {    
        $out='<a class="btn btn-info" href="'.$href.'">'.$text.'</a>';
        return $out;
    }
}
if ( ! function_exists('bootstrap_boton_default')){
    function bootstrap_boton_default($href,$text)
    {    
        $out='<a class="btn btn-primary" href="'.$href.'">'.$text.'</a>';
        return $out;
    }
}
if ( ! function_exists('bootstrap_boton_danger')){
    function bootstrap_boton_danger($href,$text)
    {    
        $out='<a class="btn btn-danger" href="'.$href.'">'.$text.'</a>';
        return $out;
    }
}
if ( ! function_exists('bootstrap_boton_negro')){
    function bootstrap_boton_negro($href,$text)
    {    
        $out='<a class="btn btn-inverse" href="'.$href.'">'.$text.'</a>';
        return $out;
    }
}
if ( ! function_exists('bootstrap_boton_link')){
    function bootstrap_boton_link($href,$text)
    {
        $out='<a class="btn btn-link" href="'.$href.'">'.$text.'</a>';
        return $out;
    }
}

